<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>


</head>
<body>
<input type="text" id="i1" >
<input type="button" value="平方" onclick="fn()">
<div>结果：0</div>

<script>
    function fn() {
        let i=document.querySelector("#i1");
        let d=document.querySelector("div");
        if(isNaN(i.value)){
            d.innerText="输入错误";
            return;
        }
        // d.innerText="结果："+i.value*i.value;
        // d.innerText="结果："+(i.value*1+i.value*1);
    //    parseInt(变量)将字符串或小数转为整数
    //    parseFloat（变量）将字符串转为小数
        d.innerText="结果："+(parseFloat(i.value)+parseFloat(i.value));


    }
</script>
</body>
</html>